package leetcode.calc._06_07;

public class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        return "{" + myToStr() + "}";
    }

    private String myToStr() {
        if (next == null) {
            return val + "";
        }
        return val + "," + next.myToStr();
    }

    public static ListNode crtNode (int[] arr) {
        ListNode res = new ListNode(arr[0]);
        ListNode pre = res;
        for (int i = 1; i < arr.length; i++) {
            ListNode tmp = new ListNode(arr[i]);
            pre.next = tmp;
            pre = tmp;
        }
        return res;
    }
}